<template>
  <div class="nation">
    <el-checkbox-group v-model="model.allergyList">
      <el-checkbox label="-1" @change="handlerCheckBox('-1')">无</el-checkbox>
      <el-checkbox label="101" @change="handlerCheckBox('101')"
        >青霉素</el-checkbox
      >
      <el-checkbox label="102" @change="handlerCheckBox('102')"
        >磺胺</el-checkbox
      >
      <el-checkbox
        label="L86902101000159"
        @change="handlerCheckBox('L86902101000159')"
        >链霉素</el-checkbox
      >
      <el-checkbox label="199" @change="handlerCheckBox('199')"
        >其他</el-checkbox
      >
      <el-input v-model="model.allergyValue" style="width:120px" />
    </el-checkbox-group>
  </div>
</template>

<script>
export default {
  props: {
    model: {
      type: Object,
      default: () => {}
    }
  },
  data() {
    return {}
  },
  methods: {
    handlerCheckBox(value) {
      // console.log(value)
      const emptyVal = "-1"
      // 1 无 5 其他
      const currentIsChecked = this.model.allergyList.includes(value)
      // 当选择无时
      if (value === emptyVal && currentIsChecked) {
        this.model.allergyList = ["-1"]
      } else if (value !== emptyVal) {
        this.model.allergyList = this.model.allergyList.filter(v => v != "-1")
      }
    }
  }
}
</script>
<style lang="scss" scoped>
.nation {
  // display: flex;
  .el-input {
    margin-left: 15px;
  }
}
</style>
